//
//  GanLuShudongDateVC.m
//  GanLuApp
//
//  Created by 暗流澎涌 on 2024/4/2.
//

#import "GanLuShudongDateVC.h"
#import "JFCalendarPickerView.h"
#import "GanLuCHooseXInqingViewControllerVC.h"
#import "GanLuLisrVC.h"
#import "GanLuXinQingSaver.h"
#import "GanLuEditInfoVC.h"
#import "GanLuHongFile.h"

@interface GanLuShudongDateVC ()
@property (weak, nonatomic) IBOutlet UILabel *monthLB;
@property (weak, nonatomic) IBOutlet UILabel *yearLb;
@property (nonatomic,strong)JFCalendarPickerView *Picker;
@property (nonatomic,strong) NSArray * AllInfoArr;
@property (weak, nonatomic) IBOutlet UIView *addPickerView;
//123
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *canlderTopMargin;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *addBottomMargin;

@end

@implementation GanLuShudongDateVC
//图片名称  对应文案
//Ganlu_niaoqing_fannao -> 烦恼
//Ganlu_niaoqing_kaixin -> 开心
//Ganlu_niaoqing_nanguo -> 难过
//Ganlu_niaoqing_pibei -> 疲惫
//Ganlu_niaoqing_shengqi -> 生气
//Ganlu_niaoqing_wuyu -> 无语
//Ganlu_niaoqing_youxian -> 悠闲

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear: animated];
    [self.navigationController.navigationBar setHidden: YES];
    [self dataresh];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self showPickView];
    if(!iPhoneX){
        self.addBottomMargin.constant = 20;
        self.canlderTopMargin.constant = 50;
    }
}


- (IBAction)click_backHome:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)clickToInfoVC:(id)sender {
    GanLuLisrVC *VC = [[GanLuLisrVC alloc]init];
    NSDateFormatter *ff = [NSDateFormatter new];
    [ff setDateFormat:@"yyyy/MM/dd"];
    VC.dateStr = [ff stringFromDate:[NSDate date]];
    [self.navigationController pushViewController:VC animated:YES];
}
-(void)showPickView{
    self.addPickerView.layer.cornerRadius = 20;
    self.addPickerView.layer.masksToBounds = YES;
    self.Picker = [JFCalendarPickerView showOnView:self.addPickerView];
    self.Picker.layer.cornerRadius = 20;
    self.Picker.layer.masksToBounds  = YES;
    
    self.Picker.today = [NSDate date];
    
    self.Picker.date = self.Picker.today;
    [self dataresh];
    self.Picker.allArr = self.AllInfoArr;
    //frame用外界控制日历的大小 可以更灵活的调用
    self.Picker.frame = CGRectMake(0, 0, self.addPickerView.frame.size.width , 360);
    
    //提供一个block给外界调用
    __weak __typeof(self)weakSelf = self;
    self.Picker.calendarBlock = ^(NSInteger day, NSInteger month, NSInteger year){
        NSLog(@"===\n日：%02ld\n月：%02ld\n年：%02ld",(long)day, (long)month, (long)year);
        //注意
        NSString *dats = [NSString stringWithFormat:@"%02ld/%02ld/%02ld",year,month,day];
        //如果点击了有心情一天，就进入编辑
        if ([GanLuXinQingSaver dateString:dats]) {
            GanLuEditInfoVC *vc = [[GanLuEditInfoVC alloc] init];
            vc.isEdit = vc;
            NSDateFormatter *form = [[NSDateFormatter alloc] init];
            [form setDateFormat:@"yyyy/MM/dd"];
            NSDate *dd = [form dateFromString:dats];
            vc.day = dd;
            vc.modalPresentationStyle = UIModalPresentationFullScreen;
            [weakSelf presentModalViewController:vc animated:YES];
        } else {
            //如果点击了没有心情一天，就进入新的页面选择心情
            GanLuCHooseXInqingViewControllerVC * chooseVC = [[GanLuCHooseXInqingViewControllerVC alloc]init];
            
            NSDateFormatter *form = [[NSDateFormatter alloc] init];
            [form setDateFormat:@"yyyy/MM/dd"];
            NSDate *dd = [form dateFromString:dats];
            chooseVC.cdate = dd;
            [weakSelf.navigationController pushViewController:chooseVC animated:YES];
        }
        
    };
    
    self.Picker.calendarMonthChangeBlock = ^(NSInteger month, NSInteger year){
        weakSelf.yearLb.text = [NSString stringWithFormat:@"%ld年",(long)year];
        NSArray *mons = @[@"一月",@"二月",@"三月",@"四月",@"五月",@"六月",@"七月",@"八月",@"九月",@"十月",@"十一月",@"十二月"];
        weakSelf.monthLB.text = mons[month - 1];
    };

}
-(void)dataresh{
    self.Picker.allArr = self.AllInfoArr;
}
- (IBAction)clickAddNew:(id)sender {
    GanLuCHooseXInqingViewControllerVC * chooseVC = [[GanLuCHooseXInqingViewControllerVC alloc]init];
    chooseVC.cdate = [NSDate date];
    [self.navigationController pushViewController:chooseVC animated:YES];
}

@end
